﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using AutoFacUtils;
using CashFlow.Db.Entity;
using CashFlow.ShopManage.Common;
using CashFlow.ShopManage.Filters;
using CashFlow.ShopManage.Models;
using CashFlow.ShopManage.Models.User;
using CashFlow.ShopManage.Models.User.Result;
using CashFlow.ShopManage.Service;
using CashFlow.ShopManage.Validator;

namespace CashFlow.ShopManage.Controllers
{
    public class UserAccountInfoController : Controller
    {
        private IUserAccountInfoService GetUserAccountInfoService() { return AutoFacHelper.Get<IUserAccountInfoService>(); }

        [HttpPost]
        [ValidatorFilter(typeof(UserIdModelValidator))]
        public ActionResult QueryByUserId(UserIdModel model)
        {
            var service = GetUserAccountInfoService();
            var entity = service.QuerySingle(x => x.UserId == model.UserId);
            var entity2 = Convert(entity);
            return MyCommonTool.CreateOperationResult(true, "", entity2);
        }

        private QueryUserAccountInfoResultModel Convert(UserAccountInfoEntity entity)
        {
            if (entity != null)
            {
                return new QueryUserAccountInfoResultModel
                {
                    UserId = entity.UserId,
                    WechatImagePath = entity.WechatCodePath,
                    AlipayImagePath = entity.AlipayCodePath,
                    Bank = entity.Bank,
                    BankAccountName = entity.BankAccountName,
                    BankCardNo = entity.BankCardNo,
                    Address = entity.Address
                };
            }
            else
            {
                return new QueryUserAccountInfoResultModel();
            }
        }
    }
}